package utils;

import android.content.Context;
import android.util.Log;
import android.widget.Filter;

import com.example.administrator.newxlmedical.R;

import java.util.ArrayList;
import java.util.List;

import beans.ComboBean;
import beans.GoodsStatisticsBean;
import beans.InventoryWarnBean;
import beans.ItemEntity;
import beans.OperateGoodsDetailsBean;
import beans.StorageWarningInfoBean;
import beans.WarningInfoBean;
import constants.Constants;
import netframe.IFuzzySearchRule;

/**
 * Created by Administrator on 2018/10/30.
 */

public class FuzzySearchUtils {

    public static List<ItemEntity> fillData(List<OperateGoodsDetailsBean.DataBean> date, int type) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (OperateGoodsDetailsBean.DataBean item : date) {
            String letter;
            String value;
            //汉字转换成拼音
            List<String> pinyinList = new ArrayList<>();
            if (type == 1) {
                pinyinList = PinyinUtil.getPinYinList(item.getGoodName());
                value = item.getGoodName();
            } else if (type == 2) {
                pinyinList = PinyinUtil.getPinYinList(item.getSpecification());
                value = item.getSpecification();
            } else if (type == 3) {
                pinyinList = PinyinUtil.getPinYinList(item.getManufacturer());
                value = item.getManufacturer();
            } else {
                pinyinList.addAll(PinyinUtil.getPinYinList(item.getGoodName()));
                pinyinList.addAll(PinyinUtil.getPinYinList(item.getSpecification()));
                pinyinList.addAll(PinyinUtil.getPinYinList(item.getManufacturer()));
                value = item.getGoodName() + item.getSpecification() + item.getManufacturer();
            }
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(value, letter, pinyinList);
            itemEntity.setmBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }

    public static List<ItemEntity> fillWarnData(List<WarningInfoBean.DataBean> date) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (WarningInfoBean.DataBean item : date) {
            String letter;
            //汉字转换成拼音
            List<String> pinyinList;
            pinyinList = PinyinUtil.getPinYinList(item.getGoodName());
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(item.getGoodName(), letter, pinyinList);
            itemEntity.setmWarnBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }
    public static List<ItemEntity> fillOldWarnData(List<StorageWarningInfoBean> date) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (StorageWarningInfoBean item : date) {
            String letter;
            //汉字转换成拼音
            List<String> pinyinList;
            pinyinList = PinyinUtil.getPinYinList(item.getGoodsName());
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(item.getGoodsName(), letter, pinyinList);
            itemEntity.setOldBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }

    public static List<ItemEntity> fillWarnInfoData(List<InventoryWarnBean.DataBean> date) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (InventoryWarnBean.DataBean item : date) {
            String letter;
            //汉字转换成拼音
            List<String> pinyinList;
            pinyinList = PinyinUtil.getPinYinList(item.getGoodName());
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(item.getGoodName(), letter, pinyinList);
            itemEntity.setmWarnInfoBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }

    public static List<ItemEntity> fillCountData(List<GoodsStatisticsBean.DataBean> date,int type) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (GoodsStatisticsBean.DataBean item : date) {
            String letter;
            String value;
            //汉字转换成拼音
            List<String> pinyinList;
            if (type == 1) {
                pinyinList = PinyinUtil.getPinYinList(item.getGoodName());
                value = item.getGoodName();
            } else {
                pinyinList = PinyinUtil.getPinYinList(item.getSpecification());
                value = item.getSpecification();
            }
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(value, letter, pinyinList);
            itemEntity.setCountBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }

    public static List<ItemEntity> fillCaridnalNumberData(List<WarningInfoBean.DataBean> date,int type) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (WarningInfoBean.DataBean item : date) {
            String letter;
            String value;
            //汉字转换成拼音
            List<String> pinyinList;
            if (type == 1) {
                pinyinList = PinyinUtil.getPinYinList(item.getGoodName());
                value = item.getGoodName();
            } else {
                pinyinList = PinyinUtil.getPinYinList(item.getSpecification());
                value = item.getSpecification();
            }
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(value, letter, pinyinList);
            itemEntity.setmWarnBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }
    public static List<ItemEntity> fillComboData(List<ComboBean.DataBean> date) {
        List<ItemEntity> sortList = new ArrayList<>();
        for (ComboBean.DataBean item : date) {
            String letter;
            //汉字转换成拼音
            List<String> pinyinList;
                pinyinList = PinyinUtil.getPinYinList(item.getPackageName());
            if (pinyinList != null && !pinyinList.isEmpty()) {
                // A-Z导航
                String letters = pinyinList.get(0).substring(0, 1).toUpperCase();
                // 正则表达式，判断首字母是否是英文字母
                if (letters.matches("[A-Z]")) {
                    letter = letters.toUpperCase();
                } else {
                    letter = "#";
                }
            } else {
                letter = "#";
            }
            ItemEntity itemEntity = new ItemEntity(item.getPackageName(), letter, pinyinList);
            itemEntity.setComboBean(item);
            sortList.add(itemEntity);
        }
        return sortList;

    }
}
